using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using Common;
using Common.Utilities;

namespace WindowsUserControl.ToolboxItems
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="tag"></param>
    public delegate void ToolboxItemSelected(object tag);

    /// <summary>
    /// 
    /// </summary>
    public class ToolboxItem : Button
    {
        /// <summary>
        /// 
        /// </summary>
        public event ToolboxItemSelected OnToolboxItemSelected;

        private string _Name;
        /// <summary></summary>
        public new string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private string _Tooltip;
        /// <summary></summary>
        public string ToolTip
        {
            get { return _Tooltip; }
            set { _Tooltip = value; }
        }

        private string _ImageName;
        /// <summary></summary>
        public string ImageName
        {
            get { return _ImageName; }
            set { _ImageName = value; }
        }

        private string _CategoryName;
        /// <summary></summary>
        public string CategoryName
        {
            get { return _CategoryName; }
            set { _CategoryName = value; }
        }

        private object _Tag;
        /// <summary></summary>
        public new object Tag
        {
            get { return _Tag; }
            set { _Tag = value; }
        }
	
	/// <summary>
	/// 
	/// </summary>
	/// <param name="name"></param>
	/// <param name="tooltip"></param>
	/// <param name="imgName"></param>
	/// <param name="categoryName"></param>
	/// <param name="tag"></param>
        public ToolboxItem(string name, string tooltip, string imgName, string categoryName, object tag):base()
        {
            this._Name = name;
            this._Tooltip = tooltip;
            this._ImageName = imgName;
            this._CategoryName = categoryName;
            this._Tag = tag;

            ImageList imgList=new ImageList();
            Image img = ResourceUtil.GetImageFromResource(Assembly.GetExecutingAssembly(), imgName);
            imgList.Images.Add(img);

            this.ImageList = imgList;
            this.ImageIndex = 0;
            this.Text = "     " + this._Name;
            this.ImageAlign = ContentAlignment.MiddleLeft;
            this.TextAlign = ContentAlignment.MiddleLeft;
            this.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
            this.ToolTip = this._Tooltip;
            this.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.FlatAppearance.BorderColor = Color.GhostWhite;
            this.FlatAppearance.BorderSize = 0;
            this.Dock = DockStyle.Top;
            this.BackColor = SystemColors.Control;
            this.AutoSize = false;
            this.Size = new Size(200, 25);

            this.MouseDown += new MouseEventHandler(ToolboxItem_MouseDown);
            this.MouseHover += new EventHandler(ToolboxItem_MouseHover);
            this.MouseLeave += new EventHandler(ToolboxItem_MouseLeave);
        }

        void ToolboxItem_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = SystemColors.Control;
        }

        void ToolboxItem_MouseHover(object sender, EventArgs e)
        {
            this.BackColor = SystemColors.ControlDark;
        }

        void ToolboxItem_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.OnToolboxItemSelected != null)
                this.OnToolboxItemSelected(this._Tag);
        }

    }
}
